 var dialogReturnValue = [];

$(function(){
	/*layer.config({
        skin:'layer-ext-espresso',
        extend:'skin/blue/style.css'
});*/
}) 
function isNotBlank(obj){
	return !isBlank(obj);
}
 function isBlank(obj){
     if(obj===undefined||obj===null||obj===""||obj==="undefined"||obj==="null"){
         return true;
     }
     return false;
 }
/**
 * 打开loading
 * @param tableid
 */
/*function closeLoading(tableid){
	 layer.closeAll('loading');
}*/
/**
 * 关闭loading
 * @param tableid
 */
/*function openLoading(tableid){
	layer.load(2,
			{ shade: [0.1,'#A1A1A1'] //0.1透明度的白色背景
			});
	setTimeout(function(){
	  layer.closeAll('loading');
	}, 6000);
}*/
function ajaxProcess(url,data,func,type,async,dataType,contentType,tableid){
	async = async === false ? false : true;
	contentType=contentType==null? "application/x-www-form-urlencoded" : contentType;
	var returnJsonData
	$.ajax({
		type : type,
		url : url,
		data : data,
		async : async,
		dataType : dataType,
		contentType:contentType,
		beforeSend : function() {
			//openLoading(tableid);
		},
		success : function(jsondata) {
			//closeLoading(tableid);
			if (typeof func === 'function') {
				func(jsondata);
			}
			//同步时，返回结果集
			if(async === false){
				returnJsonData = jsondata;
			}
		},
		complete : function() {
			//closeLoading(tableid);
		}
	});
	//同步时，返回结果集
	if(async === false){
		return returnJsonData;
	}
}
function ajaxGetData(url, data, func, async,type,tableid){
	return ajaxProcess(url, data, func,"GET", async, "json", "text/plain;charset=utf-8",tableid) ;
}
/**
 * ajax 调用方法
 * @param url 访问地址
 * @param data 提交参数
 * @param func 结果回调函数
 * @param async true异步、false同步
 * @param tableid
 * @param type
 * @returns
 */
function ajaxPostData(url, data, func, async,type,tableid) {
	return ajaxProcess(url, JSON.stringify(data), func,"POST", async, "json", "application/json;charset=utf-8",tableid) ;
}
 function ajaxPostObjectData(url, data, func, async,type,tableid) {
	 return ajaxProcess(url, data, func,"POST", async, "json",null,tableid) ;
 }
/**
 * ajax 调用方法
 * @param url 访问地址
 * @param data 提交参数
 * @param func 结果回调函数
 * @param async true异步、false同步
 * @param tableid
 * @param type
 * @returns
 */
function ajaxPostArray(url, data, func, async,type,tableid) {
    ajaxProcess(url, JSON.stringify(data), func, "POST", async, "text", 'application/json;charset=utf-8', tableid);
}
 function ajaxPostJsonData(url, data, func, async,type,tableid) {
     return ajaxProcess(url, JSON.stringify(data), func,"POST", async, "json", "application/json;charset=utf-8",tableid) ;
 }
function strToJson(str){
	var json = eval('(' + str + ')');
	return json;
} 
//截取url参数
function getUrlParam(name){
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r!=null) 
		return unescape(r[2]); 
	return null;
}

//取小数点后2位
function changeTwoDecimal(x) {  
	var f_x = parseFloat(x);  
	var f_x = Math.round(x*100)/100;  
	return f_x;  
} 

//日期 毫秒数 转化 标准格式 
function format(time, format){
    var t = new Date(time);
    var tf = function(i){return (i < 10 ? '0' : '') + i};
    return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
        switch(a){
            case 'yyyy':
                return tf(t.getFullYear());
                break;
            case 'MM':
                return tf(t.getMonth() + 1);
                break;
            case 'mm':
                return tf(t.getMinutes());
                break;
            case 'dd':
                return tf(t.getDate());
                break;
            case 'HH':
                return tf(t.getHours());
                break;
            case 'ss':
                return tf(t.getSeconds());
                break;
        }
    });
}


/*function isLogin(){
	if($.cookie('cookie_username') != undefined && $.cookie('cookie_username') != 'undefined'){
		return true;
	}else{
		window.location='/page/manager/login.html';
	}
} */
//isLogin();
function msgBox(msg,func,iconType,closeParent){
	var icon=6;
	if(iconType==="0"){
		icon=0;
	}
	if(!isNotBlank(msg)){
		msg="保存成功!";
	}
	if(msg.indexOf("失败")>-1){
		icon=5;
	}
	if(!isNotBlank(closeParent)){
		closeParent=true;
	}
		layer.msg(msg, {
			  icon: icon,
			  time: 2000 //2秒关闭（如果不配置，默认是3秒）
			}, function(index){
				if(!isNotBlank(func)&&getObjType(func) === 'function') {
					func();
				}
				if(closeParent==true){
					var index1 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index1); 
				}else{
					layer.close(index);
				}
			});  
}
function confirmBox(msg,funcMap,title,type){
	if(!isNotBlank(title)){
		title="询问";
	}
	if(!isNotBlank(type)){
		type=3;
	}
	if(getObjType(msg)=== 'object'){
		msg+=(msg.msg+"<p>"+msg.sub+"</p>");
	}
	layer.confirm(
			msg,
			{
				icon:type,
				title:title
			}, 
			function(index){
				if(getObjType(funcMap) === 'function') {
					funcMap();
				}else if(getObjType(funcMap)=== 'object'){
					funcMap.yes();
				}
			},
			function(index){
				if(getObjType(funcMap)=== 'object'&&!isNotBlank(funcMap.no)){
					funcMap.no();
				}
			}
			
	);
}

function openDialog(title,url,width,height,funcMap,type){
	
	if(!isNotBlank(title)){
		title="信息";
	}
	if(!isNotBlank(type)){
		type=2;
	}
	
	if(!isNotBlank(width)){
		width='480px';
	}
	if(!isNotBlank(height)){
		height='450px';
	}
	layer.open({
		  type:type,
		  title: title,
		  shadeClose: false,
		  shade: 0.8,
		  area: [width,height],
		  scrollbar: false,
		  content: url, //iframe的url
		  end:function(index){
			  if(getObjType(funcMap) === 'function') {
					funcMap();
				}
		  }
		
	}); 
}
function getObjType(obj){
	return typeof obj;
}

function setDialogReturnValue(key, value) {
	dialogReturnValue[key] = value;
}
function getFormJson(form){
  var a =$(form).serializeArray();    
  var o = {};
   $.each(a, function() {    
       if (o[this.name]) {    
           if (!o[this.name].push) {    
               o[this.name] = [o[this.name]];    
           }    
           o[this.name].push(this.value || '');    

       } else {    
           o[this.name] = this.value || '';    
       }    
   });    
   return o;    
};
 function checkEmailPatter(email) {
	 if(isBlank(email)) return false;
     var emailRes = (/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/);
     return emailRes.test(email.toLowerCase());
 }

 /**
  * 校验电话格式
  * @param tel
  * @return
  */
 function checkMobilePatter(mobile){
     if(isBlank(mobile)) return false;
     if(mobile.indexOf('Q')==0) return true;
     var  mobileRes=(/^(13[0-9]|15[0123456789]|18[0123456789]|14[57]|17[012356789])[0-9]{8}$/);
     var  mat=mobileRes.test(mobile);
     return mat||(/^0886[0-9]{9}$/).test(mobile);
 }
function goBack(type) {
	if(type==1){
        self.location=document.referrer;
	}else{
    	history.go(-1);
	}
}
